package com.jiahua.admin.biz.dao.impl;

import java.util.List;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jiahua.admin.biz.dao.InventoryCategoryDao;
import com.jiahua.user.biz.model.InventoryCategory;

public class InventoryCategoryDaoImpl extends HibernateDaoSupport implements InventoryCategoryDao {

	final Logger logger = Logger.getLogger(InventoryCategoryDaoImpl.class.getName());

	@Override
	public boolean saveInventoryCategory(InventoryCategory inventoryCategory) {
		boolean result = true;
		try {
			inventoryCategory.setCategoryID(UUID.randomUUID().toString());
			getHibernateTemplate().save(inventoryCategory);
			logger.info("InventoryCategoryDaoImpl save successful.");
		} catch (DataAccessException e) {
			result = false;
			logger.error(e.getLocalizedMessage());
			e.printStackTrace();
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<InventoryCategory> listInventoryCategory() {
		return getHibernateTemplate().find("from InventoryCategory");
	}

	@Override
	public InventoryCategory getInventoryCategoryById(String id) {
		return getHibernateTemplate().get(InventoryCategory.class, id);
	}

}
